package com.aaa.service.impl;

import com.aaa.dao.TRoleMenuMapper;
import com.aaa.entity.TRoleMenu;
import com.aaa.service.TRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (TRoleMenu)表服务实现类
 *
 * @author yuyongli
 * @since 2022-10-26 09:29:54
 */
@Service
public class TRoleMenuServiceImpl implements TRoleMenuService {
   @Autowired
   private TRoleMenuMapper tRoleMenuMapper;

    @Override
    public boolean updRoleMenu(Integer rid, String mids) {
        // mids  1,2,3,4,5

        // 删除当前的角色的id所拥有的菜单
        TRoleMenu tRoleMenu = new TRoleMenu();
        tRoleMenu.setRid(rid);
        int delete = tRoleMenuMapper.delete(tRoleMenu);

        // 2. 给当前的角色添加新的菜单的信息
        if(mids!=null){
            String[] misstr = mids.split(",");
            for (String mid : misstr) {
                int i = Integer.parseInt(mid);
                TRoleMenu tRoleMenu1 = new TRoleMenu(rid, i);
                tRoleMenuMapper.insert(tRoleMenu1);

            }
        }
        return delete>=0;
    }
}

